import { BotApi, XinghanApi, plugin } from '../../model/api/api.js'
import fetch from "node-fetch";

export class Xinghan_Api extends plugin {
    constructor() {
        super(BotApi.SuperInex.getUser({
            rule: [
                {
                    reg: '^#随机一言$',
                    fnc: 'suijiyiyan'
                },
                {
                    reg: '^#(抱|抓|拍|顶|咬|指|笑|甩|嗨|打).*$',
                    fnc: 'gif'
                },
                {
                    reg: '^#(幽灵|警察|抑郁|单身|举牌|摸头|羡慕).*$',
                    fnc: 'pic'
                }
            ]
        }))
    }
    async suijiyiyan(e) {
        var url = "https://v.api.aa1.cn/api/yiyan/index.php";
        let response = await fetch(url);
        let text = await response.text()
        var pattern = /<p>(.*?)<\/p>/;
        var result = text.match(pattern);
        if (result && result.length >= 2) {
            var content = result[1];
            e.reply(content);
        } else {
            e.reply("获取出错！");
        }
        return
    }

    async gif(e) {
        //没有at信息直接返回,不执行
        let url = ""
        let isat = e.message.some(item => item.type === 'at');
        if (!isat) {
            return;
        }
        let str = e.msg
        var extractedText = str.slice(1, 2);
        if (extractedText == "抱") {
            url = "https://api.xingzhige.com/API/baororo/?qq="
        }
        if (extractedText == "抓") {
            url = "https://api.xingzhige.com/API/grab/?qq="
        }
        if (extractedText == "拍") {
            url = "https://api.xingzhige.com/API/paigua/?qq="
        }
        if (extractedText == "顶") {
            url = "https://api.xingzhige.com/API/dingqiu/?qq="
        }
        if (extractedText == "咬") {
            url = "https://api.xingzhige.com/API/bite/?qq="
        }
        if (extractedText == "指") {
            url = "https://api.xingzhige.com/API/Lookatthis/?qq="
        }
        if (extractedText == "笑") {
            url = "https://api.xingzhige.com/API/LaughTogether/?qq="
        }
        if (extractedText == "嗨") {
            url = "https://api.xingzhige.com/API/FortuneCat/?qq="
        }
        if (extractedText == "甩") {
            url = "https://api.xingzhige.com/API/DanceChickenLeg/?qq="
        }
        if (extractedText == "打") {
            url = "https://api.xingzhige.com/API/pound/?qq="
        }
        if (url == "") {
            e.reply("异常")
            return;
        }
        //获取at信息
        let atItem = e.message.filter(item => item.type === 'at');
        //对方qq
        let qq = atItem[0].qq;
        url += qq
        e.reply(segment.image(url))
        return
    }

    async pic(e) {
        //没有at信息直接返回,不执行
        let url = ""
        let isat = e.message.some(item => item.type === 'at');
        if (!isat) {
            return;
        }
        let str = e.msg
        var extractedText = str.slice(1, 3);
        if (extractedText == "幽灵") {
            url = "http://119.23.246.247/api/lieshou.php?qq="
        }
        if (extractedText == "警察") {
            url = "http://119.23.246.247/api/Policebadge.php?qq="
        }
        if (extractedText == "抑郁") {
            url = "http://119.23.246.247/api/bao.php?qq="
        }
        if (extractedText == "单身") {
            url = "http://119.23.246.247/api/dsg.php?qq="
        }
        if (extractedText == "举牌") {
            url = "http://119.23.246.247/api/ju.php?qq="
        }
        if (extractedText == "摸头") {
            url = "http://119.23.246.247/api/motou.php?qq="
        }
        if (extractedText == "羡慕") {
            url = "http://119.23.246.247/api/xianmu.php?qq="
        }
        if (url == "") {
            e.reply("异常")
            return;
        }
        //获取at信息
        let atItem = e.message.filter(item => item.type === 'at');
        //对方qq
        let qq = atItem[0].qq;
        url += qq
        e.reply(segment.image(url))
        return
    }
}